package zcw.com.lib_leet_code;

import java.util.Arrays;

/**
 * Created by 朱城委 on 2021/7/22.<br><br>
 *
 * 数组中的第K个最大元素
 */
public class Topic215 {

    public static void main(String[] args) {
        Topic215 instance = new Topic215();

        int[] array = new int[] {3,2,1,5,6,4};
        System.out.println(instance.findKthLargest(array, 2));

        array = new int[] {3,2,3,1,2,4,5,5,6};
        System.out.println(instance.findKthLargest(array, 4));
    }

    public int findKthLargest(int[] nums, int k) {
        Arrays.sort(nums);
        return nums[nums.length - k];
    }
}
